﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ECONTACT.DataLayer
{
    public class PhuHuynhData
    {
        DataService m_PhuHuynhData = new DataService();
        public DataTable LayDsPhuHuynh()
        {
            SqlCommand cmd = new SqlCommand("SELECT * FROM PHUHUYNH");
            m_PhuHuynhData.Load(cmd);
            return m_PhuHuynhData;
        }

        //public void LuuPhuHuynh(String MaPH,String TenPH, String SDT, DateTime NgaySinh, String DiaChi)
        public String LuuPhuHuynh(String TenPH, String SDT, DateTime NgaySinh, String DiaChi)
        {
            try
            {
                //SqlCommand cmd = new SqlCommand("INSERT INTO PHUHUYNH VALUES(@MaPH,@TenPH,@NgaySinh,@DiaChi,@SDT)");
                SqlCommand cmd = new SqlCommand("sp_ThemPhuHuynh");
                //cmd.Parameters.Add("MaPH", SqlDbType.VarChar).Value = MaPH;
                cmd.Parameters.Add("@TenPH", SqlDbType.NVarChar).Value = TenPH;
                cmd.Parameters.Add("@NgaySinh", SqlDbType.DateTime).Value = NgaySinh;
                cmd.Parameters.Add("@SDT", SqlDbType.VarChar).Value = SDT;
                cmd.Parameters.Add("@DiaChi", SqlDbType.NVarChar).Value = DiaChi;

                m_PhuHuynhData.LoadProc(cmd);
            }
            catch (System.Exception ex)
            {
                return ex.Message;
            }
            return "Success";
        }

        public String UpdatePhuHuynh(String MaPH, String TenPH, String SDT, DateTime NgaySinh, String DiaChi)
        {
            try
            {
                //SqlCommand cmd = new SqlCommand("UPDATE PHUHUYNH SET TenPH = @TenPH,NgaySinh = @NgaySinh,DiaChi = @DiaChi,SDT = @SDT where MaPH = @MaPH");
                SqlCommand cmd = new SqlCommand("sp_CapNhatPhuHuynh");
                cmd.Parameters.Add("@MaPH", SqlDbType.VarChar).Value = MaPH;
                cmd.Parameters.Add("@TenPH", SqlDbType.NVarChar).Value = TenPH;
                cmd.Parameters.Add("@NgaySinh", SqlDbType.DateTime).Value = NgaySinh;
                cmd.Parameters.Add("@SDT", SqlDbType.VarChar).Value = SDT;
                cmd.Parameters.Add("@DiaChi", SqlDbType.NVarChar).Value = DiaChi;

                m_PhuHuynhData.LoadProc(cmd);
            }
            catch (System.Exception ex)
            {
                return ex.Message;
            }
            return "Success";
        }

        public void DeletePhuHuynh(String MaPH)
        {
            //SqlCommand cmd = new SqlCommand("DELETE FROM PHUHUYNH where MaPH = @MaPH");
            SqlCommand cmd = new SqlCommand("sp_XoaPhuHuynh");
            cmd.Parameters.Add("@MAPHUHUYNH", SqlDbType.Int).Value = Convert.ToInt32(MaPH);

            m_PhuHuynhData.LoadProc(cmd);
        }
    }
}
